using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace MarcoBarzaghi.Diagnostics
{
    class Program
    {        
        static void Main(string[] args)
        {
            IPAddress addressGroup;
            int groupPort;

            #region Read input arguments
            if (args.Length < 2)
            {
                Console.WriteLine("Invalid number of arguments.");
                PrintUsage();
                return;
            }

            string ip_value = args[0];
            string port_value = args[1];

            try
            {
                addressGroup = IPAddress.Parse(ip_value);
                groupPort = int.Parse(port_value);                
            }
            catch
            {
                Console.WriteLine("Invalid format arguments.");
                PrintUsage();
                return;
            }
            #endregion

            UpdTraceListenerProvider provider = new UpdTraceListenerProvider(addressGroup, groupPort);
            provider.StartListening();
            
            Console.WriteLine("Type <Enter> to exit.");
            Console.ReadLine();

            provider.StopListening();
        }

        private static void PrintUsage()
        {
            Console.WriteLine("Usage: {0}.exe <ip> <port>", typeof(Program).Assembly.FullName);
        }

    }
}
